/**
 * Alibaba.com.cn Inc.
 * Copyright (c) 2004-2021 All Rights Reserved.
 */
package com.starlink.client.jd.request;

import com.lop.open.api.sdk.domain.jdcloudprint.PullDataService.pullData.PullDataReqDTO;
import com.starlink.client.jd.request.base.WayBillInfoRequest;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zhanghong
 * @version PullDataRequest.java, v 0.1 2024/5/18 13:09 下午 PullDataRequest Exp $$
 */
@Data
@NoArgsConstructor
public class PullDataRequest implements Serializable {
    /**
     * 运单信息列表。最多支持10条
     * @required true
     */
    private List<WayBillInfoRequest> wayBillInfos;
    /**
     * 商家信息
     * @required true
     */
    private Map<String, String> parameters;
    /**
     * 每次请求唯一，本次获取打印数据请求ID，根据此请求ID可快速定位并进行排查。长度10-50
     * @required true
     */
    private String objectId;


    public PullDataReqDTO toPullDataRequest(String customerCode) {
        PullDataReqDTO pullDataReqDTO = new PullDataReqDTO();
        pullDataReqDTO.setCpCode("JD");
        if (CollectionUtils.isNotEmpty(wayBillInfos)) {
            pullDataReqDTO.setWayBillInfos(wayBillInfos.stream().map(WayBillInfoRequest::toWayBillInfo).collect(Collectors.toList()));
        }
        Map<String, String> parameters = new HashMap<>();
        parameters.put("ewCustomerCode", customerCode);
        pullDataReqDTO.setParameters(parameters);
        pullDataReqDTO.setObjectId(this.objectId);
        return pullDataReqDTO;
    }
}
